﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace ColourPicker
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void pictureBox1_DoubleClick(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                pictureBox1.BackColor = colorDialog1.Color;
                string color;
                color = string.Format("{0:X8}", pictureBox1.BackColor.ToArgb());
                textBox4.Text = color;
                color = color.Remove(color.IndexOf("x") + 1, 2);
                textBox1.Text = color + "FF";
                textBox2.Text = color;
            }
        }

        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            toolTip1.ToolTipIcon = ToolTipIcon.Info;
            toolTip1.ToolTipTitle = "ColorPicker";
            toolTip1.SetToolTip(pictureBox1, "DoubleClick To Pick Up A Color"); 
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox3.Text == "")
            {
                toolTip1.ToolTipTitle = "ColorPicker";
                toolTip1.ToolTipIcon = ToolTipIcon.Error;
                System.Media.SystemSounds.Beep.Play();  
                toolTip1.Show("Please enter a name for the color!",textBox3, textBox3.Width / 2, textBox3.Height / 4 - 15, 3000); 
            }
            else if (textBox1.Text == "")
            {
                toolTip1.ToolTipTitle = "ColorPicker";
                toolTip1.ToolTipIcon = ToolTipIcon.Error;
                System.Media.SystemSounds.Beep.Play();
                toolTip1.Show("No color selected!", textBox1, textBox1.Width / 2, textBox1.Height / 4 - 15, 3000);
            }
            else
            {
                Clipboard.SetText("#define " + textBox3.Text + " 0x" + textBox1.Text);    
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox3.Text == "")
            {
                toolTip1.ToolTipTitle = "ColorPicker";
                toolTip1.ToolTipIcon = ToolTipIcon.Error;
                System.Media.SystemSounds.Beep.Play();
                toolTip1.Show("Please enter a name for the color!", textBox3, textBox3.Width / 2, textBox3.Height / 4 - 15, 3000);
            }
            else if (textBox1.Text == "")
            {
                toolTip1.ToolTipTitle = "ColorPicker";
                toolTip1.ToolTipIcon = ToolTipIcon.Error;
                System.Media.SystemSounds.Beep.Play();
                toolTip1.Show("No color selected!", textBox1, textBox1.Width / 2, textBox1.Height / 4 - 15, 3000);
            }
            else
            {
                listBox1.Items.Add("#define " + textBox3.Text + " 0x" + textBox1.Text);  
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (listBox1.Items.Count == 0)
            {
                toolTip1.ToolTipTitle = "ColorPicker";
                toolTip1.ToolTipIcon = ToolTipIcon.Error;
                System.Media.SystemSounds.Beep.Play();
                toolTip1.Show("No items added!", listBox1, listBox1.Width / 2, listBox1.Height / 4 - 15, 3000);
            }
            else
            {
                string data = "";   
                foreach (string t in listBox1.Items)
                {
                    data = data + t + "\r\n";  
                }
                Clipboard.SetText(data);
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear(); 
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox4.Text == "")
            {
                toolTip1.ToolTipTitle = "ColorPicker";
                toolTip1.ToolTipIcon = ToolTipIcon.Error;
                System.Media.SystemSounds.Beep.Play();
                toolTip1.Show("No color selected!", textBox4, textBox4.Width / 2, textBox4.Height / 4 - 15, 3000);
            }
            else
            {
                Clipboard.SetText("0x" + textBox4.Text);  
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (textBox2.Text == "")
            {
                toolTip1.ToolTipTitle = "ColorPicker";
                toolTip1.ToolTipIcon = ToolTipIcon.Error;
                System.Media.SystemSounds.Beep.Play();
                toolTip1.Show("No color selected!", textBox2, textBox2.Width / 2, textBox2.Height / 4 - 15, 3000);
            }
            else
            {
                Clipboard.SetText("#" + textBox2.Text);
            }
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            aboutBox AB = new aboutBox();
            AB.ShowDialog(); 
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("http://thedarkjoker94.cer33.com/"); 
        }
    }
}
